//
//  DECXManager.m
//  DECXInStore
//
//  Created by 程强 on 15/12/14.
//  Copyright © 2015年 程强. All rights reserved.
//

#import "DECXManager.h"
#import "DECXCategory.h"
#import "DECXProductOwner.h"
#import "DECXPictureFile.h"
#import "DECXStoreOrder.h"
#import "DECXContractObj.h"
#import "DECXStoreObj.h"
#import "DECXShipObj.h"
#import "DECXDriverObj.h"
#import "DECXDeliveryOrder.h"

@implementation DECXManager
- (DSASubject *)login:(NSString *)account pwd:(NSString *)pwd
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:account,@"username",
                         pwd,@"password", nil];//,@"depot",@"85"
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@login", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DECXUser *user = [[DECXUser alloc]initWithResponse:dic[@"content"]];
        [subject sendNext:user];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)seatNoLogin:(NSString *)seat pwd:(NSString *)pwd
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:seat,@"userseat",
                         pwd,@"password", nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@seatLogin", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DECXUser *user = [[DECXUser alloc]initWithResponse:dic[@"content"]];
        [subject sendNext:user];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)productOwner:(NSString *)seatNo
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:seatNo,@"username",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@checkUser", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        DECXProductOwner *owner = [[DECXProductOwner alloc]initWithResponse:dic[@"content"]];
        [subject sendNext:owner];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)category
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@getThirdCategory", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSArray *arr = parse.responseJsonOB[@"content"];
        NSMutableArray *retAry = [[NSMutableArray alloc]initWithCapacity:0];
        for (NSDictionary *dic in arr) {
            DECXCategory *caty = [[DECXCategory alloc]initWithResponse:dic];
            [retAry addObject:caty];
        }
        [subject sendNext:retAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)uploadFile:(UIImage *)origialImage thumbnail:(UIImage *)image prove:(BOOL)prove
{
    NSData *oriData = UIImageJPEGRepresentation(origialImage,1.0);
    NSData *thumData = UIImageJPEGRepresentation(image,1.0);
    
    NSString *oriName = [self fileNameThum:NO prove:prove];
    NSString *thumName = [self fileNameThum:YES prove:prove];
    DSASubject *subject = [DSASubject subject];
    [KKHttpServices postUploadFile:oriData oriName:oriName thumbnail:thumData thumname:thumName success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB[@"content"];
        DECXPictureFile *file = [[DECXPictureFile alloc] initWithResponse:dic];
        [subject sendNext:file];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(AFHTTPRequestOperation *operation) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [operation cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
- (NSString *)fileNameThum:(BOOL)small prove:(BOOL)prove
{
    NSString *timeStemp = [ToolKit nowTimeStamp];
    NSInteger i = (100 + (arc4random() % (1000 - 100 + 1)));
    if (small) {
        if (prove) {
            timeStemp = [NSString stringWithFormat:@"prove_%@",timeStemp];
        }
        timeStemp = [timeStemp stringByAppendingString:[NSString stringWithFormat:@"%ld_small.png",(long)i]];
    }else{
        if (prove) {
            timeStemp = [NSString stringWithFormat:@"prove_%@",timeStemp];
        }
        timeStemp = [timeStemp stringByAppendingString:[NSString stringWithFormat:@"%ld.png",(long)i]];
    }
    return timeStemp;
}
- (DSASubject *)commitStore:(NSString *)userid storeOrder:(DECXStoreOrderCommitModel *)model
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         model.getlist_id,@"getlist_id",
                         model.mark,@"mark",
                         model.img,@"img",
                         model.img_small,@"img_small",
                         model.goods_owner,@"goods_owner",
                         model.goods_owner_mobile,@"goods_owner_mobile",
                         model.goods_owner_phone,@"goods_owner_phone",
                         model.goods_owner_email,@"goods_owner_email",
                         model.goods_owner_prove,@"goods_owner_prove",
                         model.goods_owner_prove_small,@"goods_owner_prove_small",
                         model.inner_weight,@"inner_weight",
                         model.goods_place,@"goods_place",
                         model.goods_type,@"goods_type",
                         model.depot_quality,@"depot_quality",
                         model.stack,@"stack",
                         model.depot_responsible,@"depot_responsible",
                         model.depot_responsible_id,@"depot_responsible_id",
                         model.responsible_mobile,@"responsible_mobile",
                         model.responsible_phone,@"responsible_phone",
                         model.responsible_email,@"responsible_email",
                         model.depot_addr,@"depot_addr",
                         model.depot_id,@"depot_id",
                         @"iOS",@"plat",
                         model.isPiao,@"isPiao",
                         model.shipId,@"shipId",
                         nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@insert", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        [subject sendNext:dic];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)storeOrderList:(NSString *)userid type:(NSString *)type
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:userid,@"id",type,@"type",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@showList", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSArray *arr = parse.responseJsonOB[@"content"];
        NSMutableArray *retAry = [[NSMutableArray alloc] initWithCapacity:0];
        for (NSDictionary *dic in arr) {
            DECXStoreOrder *order = [[DECXStoreOrder alloc] initWithResponse:dic];
            [retAry addObject:order];
        }
        [subject sendNext:retAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)checkVersionUpdate
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=CheckVersionURL;
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        [subject sendNext:dic];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)changePwd:(NSString *)userid password:(NSString *)password newpassword:(NSString *)newpassword
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:userid,@"id",password,@"password",newpassword,@"newpassword",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@changePwd", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *arr = parse.responseJsonOB[@"content"];
        [subject sendNext:arr];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)getContractInfo:(NSString *)orderId
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:orderId,@"order",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@getInfoByOrder", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *arr = parse.responseJsonOB[@"content"];
        DECXContractObj *contract = [[DECXContractObj alloc]initWithResponse:arr];
        [subject sendNext:contract];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)getStoreInfo:(NSString *)depotId
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:depotId,@"depot_id",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@getDepot", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *arr = parse.responseJsonOB[@"content"];
        DECXStoreObj *store = [[DECXStoreObj alloc]initWithResponse:arr];
        [subject sendNext:store];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)getStoreList
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@get_depot", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSArray *arr = parse.responseJsonOB[@"content"];
        NSMutableArray *retAry = @[].mutableCopy;
        for (NSDictionary *mdic in arr) {
            DECXStoreObj *store = [[DECXStoreObj alloc]initWithResponse:mdic];
            [retAry addObject:store];
        }
        [subject sendNext:retAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)commitContractStore:(NSString *)userid contractOrder:(DECXContractOrderCommitModel *)model
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         model.getlist_id,@"getlist_id",
                         model.mark,@"mark",
                         model.img,@"img",
                         model.img_small,@"img_small",
                         model.goods_owner,@"goods_owner",
                         model.goods_owner_mobile,@"goods_owner_mobile",
                         model.goods_owner_phone,@"goods_owner_phone",
                         model.goods_owner_email,@"goods_owner_email",
                         model.goods_owner_prove,@"goods_owner_prove",
                         model.goods_owner_prove_small,@"goods_owner_prove_small",
                         model.inner_weight,@"inner_weight",
                         model.goods_place,@"goods_place",
                         model.goods_type,@"goods_type",
                         model.depot_quality,@"depot_quality",
                         model.stack,@"stack",
                         model.depot_responsible,@"depot_responsible",
                         model.depot_responsible_id,@"depot_responsible_id",
                         model.responsible_mobile,@"responsible_mobile",
                         model.responsible_phone,@"responsible_phone",
                         model.responsible_email,@"responsible_email",
                         model.depot_addr,@"depot_addr",
                         model.depot_id,@"depot_id",
                         @"iOS",@"plat",
                         model.brand_id,@"brand_id",
                         model.brand_price,@"brand_price",
                         nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@Warehousing", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        [subject sendNext:dic];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)getShipCompanyList
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@ship", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:nil success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSArray *arr = parse.responseJsonOB[@"content"];
        NSMutableArray *retAry = @[].mutableCopy;
        for (NSDictionary *mdic in arr) {
            DECXShipObj *store = [[DECXShipObj alloc]initWithResponse:mdic];
            [retAry addObject:store];
        }
        [subject sendNext:retAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)getOrderDetails:(NSString *)list_id
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:list_id,@"list_id",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@showinfo", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB[@"content"];
        DECXStoreOrderCommitModel *model = [[DECXStoreOrderCommitModel alloc]initWithResponseDic:dic];
        [subject sendNext:model];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)verifyOrder:(NSString *)list_id state:(NSString *)state
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:list_id,@"list_id",state,@"state",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@showupdate", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB[@"content"];
        [subject sendNext:dic];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)oneKeyRegisterSeatWithName:(NSString *)name phone:(NSString *)phone type:(NSString *)type
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:name,@"user_tname",phone,@"user_phone",type,@"user_type",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@userregister", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB[@"content"];
        DECXUser *user = [[DECXUser alloc]initWithOneKeyResponse:dic];
        [subject sendNext:user];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)addDriver:(NSString *)name phone:(NSString *)phone carNo:(NSString *)carNo warehouse:(NSString *)depot_id idCard:(NSString *)idCard
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:name,@"user_name",phone,@"phone",carNo,@"car_code",depot_id,@"depot_id",idCard,@"card_no",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@driveradd", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB[@"content"];
        [subject sendNext:dic];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)driverList:(NSString *)depot_id
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:depot_id,@"depot_id",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@driverlist", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSArray *ary = parse.responseJsonOB[@"content"];
        NSMutableArray *tempAry = @[].mutableCopy;
        for (NSDictionary *mdic in ary) {
            DECXDriverObj *driver = [[DECXDriverObj alloc]initWithResponse:mdic];
            [tempAry addObject:driver];
        }
        [subject sendNext:tempAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)driverDelete:(NSString *)driver_id
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:driver_id,@"id",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@driverdelete", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *ary = parse.responseJsonOB;
        [subject sendNext:ary];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)deliveryProduct:(NSString *)origin_listid weight:(NSString *)get_weight user_id:(NSString *)user_id depot_id:(NSString *)depot_id driver:(NSString *)driver type:(NSString *)type
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:origin_listid,@"origin_listid",get_weight,@"get_weight",user_id,@"user_id",depot_id,@"depot_id",driver,@"driver",type,@"type",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@getlist", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *ary = parse.responseJsonOB;
        [subject sendNext:ary];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)deliveryList:(NSString *)user_id type:(NSString *)type
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:user_id,@"user_id",type,@"get_type",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@listdriverd", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSArray *ary = parse.responseJsonOB[@"content"];
        NSMutableArray *tempAry = @[].mutableCopy;
        for (NSDictionary *mdic in ary) {
            DECXDeliveryOrder *order = [[DECXDeliveryOrder alloc]initWithResponse:mdic];
            [tempAry addObject:order];
        }
        [subject sendNext:tempAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)searchOrderByGetListID:(NSString *)getlist_id depot:(NSString *)depot_id type:(NSInteger)type
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:getlist_id,@"getlist_id",depot_id,@"depot_id",@(type),@"type",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@getlistt", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSArray *arr = parse.responseJsonOB[@"content"];
        NSMutableArray *retAry = [[NSMutableArray alloc] initWithCapacity:0];
        for (NSDictionary *dic in arr) {
            DECXStoreOrder *order = [[DECXStoreOrder alloc] initWithResponse:dic];
            [retAry addObject:order];
        }
        [subject sendNext:retAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)scanGetDeliveryOrderByGetListID:(NSString *)getListId uid:(NSString *)uid depotID:(NSString *)did
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:getListId,@"get_list",did,@"depot_id",uid,@"user_id",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@get_list", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *arr = parse.responseJsonOB[@"content"];
        DECXDeliveryOrder *order = [[DECXDeliveryOrder alloc] initWithResponse:arr];
        [subject sendNext:order];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)confirmOutOfStock:(NSString *)getListId
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:getListId,@"get_list",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@delivery", ServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(AFHTTPRequestOperation *operation, KKHttpParse *parse) {
        NSDictionary *arr = parse.responseJsonOB[@"content"];
        DECXDeliveryOrder *order = [[DECXDeliveryOrder alloc] initWithResponse:arr];
        [subject sendNext:order];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    }];
    return subject;
}
@end
